package com.ruoyi.dance.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.dance.domain.vo.DanceInformationVo;
import com.ruoyi.dance.domain.bo.DanceInformationBo;
import com.ruoyi.dance.service.IDanceInformationService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 新闻资讯
 *
 * @author hly
 * @date 2024-01-21
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/Dance/information")
public class DanceInformationController extends BaseController {

    private final IDanceInformationService iDanceInformationService;

    /**
     * 查询新闻资讯列表
     */
    @SaCheckPermission("Dance:information:list")
    @GetMapping("/list")
    public TableDataInfo<DanceInformationVo> list(DanceInformationBo bo, PageQuery pageQuery) {
        return iDanceInformationService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出新闻资讯列表
     */
    @SaCheckPermission("Dance:information:export")
    @Log(title = "新闻资讯", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(DanceInformationBo bo, HttpServletResponse response) {
        List<DanceInformationVo> list = iDanceInformationService.queryList(bo);
        ExcelUtil.exportExcel(list, "新闻资讯", DanceInformationVo.class, response);
    }

    /**
     * 获取新闻资讯详细信息
     *
     * @param infoId 主键
     */
    @SaCheckPermission("Dance:information:query")
    @GetMapping("/{infoId}")
    public R<DanceInformationVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long infoId) {
        return R.ok(iDanceInformationService.queryById(infoId));
    }

    /**
     * 新增新闻资讯
     */
    @SaCheckPermission("Dance:information:add")
    @Log(title = "新闻资讯", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody DanceInformationBo bo) {
        return toAjax(iDanceInformationService.insertByBo(bo));
    }

    /**
     * 修改新闻资讯
     */
    @SaCheckPermission("Dance:information:edit")
    @Log(title = "新闻资讯", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody DanceInformationBo bo) {
        return toAjax(iDanceInformationService.updateByBo(bo));
    }

    /**
     * 删除新闻资讯
     *
     * @param infoIds 主键串
     */
    @SaCheckPermission("Dance:information:remove")
    @Log(title = "新闻资讯", businessType = BusinessType.DELETE)
    @DeleteMapping("/{infoIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] infoIds) {
        return toAjax(iDanceInformationService.deleteWithValidByIds(Arrays.asList(infoIds), true));
    }
}
